<template>
	<view class="page" :style="'height:' + height + 'rpx'">
		<view class="right_item">
			<view class="right_discribe">
				<view class="discribe_title">公开</view>
				<view class="discribe_details">所有人可见</view>
			</view>
			<view class="right_switch">
				<switch color="#23b8ff" :checked="open" disabled @click="setOpen(1)" />
			</view>
		</view>
		<view class="right_item">
			<view class="right_discribe">
				<view class="discribe_title">私密</view>
				<view class="discribe_details">仅自己可见</view>
			</view>
			<view class="right_switch">
				<switch color="#23b8ff" :checked="private" disabled @click="setPrivate(2)" />
			</view>
		</view>
		<view class="right_item">
			<view class="right_discribe">
				<view class="discribe_title">部分可见</view>
				<view class="discribe_details">选中成员可见</view>
			</view>
			<view class="right_switch">
				<switch color="#23b8ff" :checked="someOneCan" disabled @click="setSomeOneCan(3)" />
			</view>
		</view>
		<view :class="someOneCanContent + ' common'">
			<view class="item" v-for="(item,index) in someOneCanChoose" :key="index" :id="'id-' + index">
				<view class="person_sex iconfont icon-renyuan1"
					:style="{'color': (item.source.sex == '男' ? '#3d8cff':'#EE82EE')}"></view>
				<view class="person_name">{{item.source.name}}</view>
			</view>
			<view class="item add" @click="addSomeOneCan()">
				<view class="iconfont icon-tianjia1"></view>
				<view style="font-size: 20rpx;">添加</view>
			</view>
			<view class="item add" @click="deleteSomeOneCan()" v-if="someOneCanChoose.length != 0">
				<view class="iconfont icon-jianshao"></view>
				<view style="font-size: 20rpx;">删除</view>
			</view>
		</view>
		<view class="right_item">
			<view class="right_discribe">
				<view class="discribe_title">不给谁看</view>
				<view class="discribe_details">选中成员不可见</view>
			</view>
			<view class="right_switch">
				<switch @change="switch1Change" color="#23b8ff" :checked="someOneCanNot" disabled
					@click="setSomeOneCanNot(4)" />
			</view>
		</view>
		<view :class="someOneCanNotContent + ' common'">
			<view class="item" v-for="(item,index) in someOneCanNotChoose" :key="index" :id="'id-' + index">
				<view class="person_sex iconfont icon-renyuan1"
					:style="{'color': (item.source.sex == '男' ? '#3d8cff':'#EE82EE')}"></view>
				<view class="person_name">{{item.source.name}}</view>
			</view>
			<view class="item add" @click="addSomeOneCanNot()">
				<view class="iconfont icon-tianjia1"></view>
				<view style="font-size: 20rpx;">添加</view>
			</view>
			<view class="item add" @click="deleteSomeOneCanNot()" v-if="someOneCanNotChoose.length != 0">
				<view class="iconfont icon-jianshao"></view>
				<view style="font-size: 20rpx;">删除</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(options) {
			// console.log(options, '配置')
			let that = this;
			this.header.Authority = uni.getStorageSync("Authority");
			
			uni.getSystemInfo({
				success: function(res) {
					let pxToRpxScale = 750 / res.windowWidth;
					// console.log(res.windowHeight);

					that.height = res.windowHeight * pxToRpxScale;
					// console.log(that.height)
				}
			});


			// this.someOneCan = true
			if (this.someOneCan) {
				this.someOneCanContent = 'someOneCanContent';
				// this.situation = 'addSomeOneCan'
			}
			if (this.someOneCanNot) {
				this.someOneCanNotContent = 'someOneCanContent'
			}
			// console.log(options.addSomeOneCan == 'true')


		},
		onShow() {
			// console.log('显示')
			this.getRight()
		},
		data() {
			return {
				height: 0,
				open: false,
				private: false,
				someOneCan: false,
				someOneCanNot: false,
				situation: '', //当前是给谁看还是不给谁看
				//rightArray: [true,false,false,false], 本来使用数组，但是数值变化时，switch监听不到
				setRightParams: { //更改权限的参数
					setting: ""
				},
				current: ['someOneCan'],
				someOneCanContent: 'content',
				someOneCanNotContent: 'content',
				someOneCanChoose: [], //用于存放给谁看的数组
				someOneCanNotChoose: [], //用于存放不给谁看的数组
				header: {},
				isReturn: false

			}
		},
		methods: {
			switchModal(title, index) {
				let that = this;
				let active = '设置';
				// this.isReturn = false; //重新设置的话，就不再是重添加或删除的页面返回了
				// console.log(this.rightArray[index]);
				let rightArray = [];
				rightArray[0] = this.open;
				rightArray[1] = this.private;
				rightArray[2] = this.someOneCan;
				rightArray[3] = this.someOneCanNot
				if (rightArray[index - 1]) {
					active = '取消'
				} else {
					active = '设置'
				}
				uni.showModal({
					title: '提示',
					content: active + '觅他权限为' + title + '?',
					success: function(res) {
						if (res.confirm) {
							if (active == '设置') {
								// console.log('shez');
								that.open = false;
								that.private = false;
								that.someOneCan = false;
								that.someOneCanNot = false;
								that.someOneCanContent = 'content';
								that.someOneCanNotContent = 'content';
								switch (index) {
									case 1: {
										that.open = true;
										break;
									}
									case 2: {
										that.private = true;
										break;
									}
									case 3: {
										that.someOneCan = true;
										that.someOneCanContent = 'someOneCanContent';
										that.detailPrivacygetting(3)
										break;
									}
									case 4: {
										that.someOneCanNot = true;
										that.someOneCanNotContent = 'someOneCanContent';
										that.detailPrivacygetting(4)
										break;
									}
								}

							} else {
								// console.log('zhix')
								//确定哪个开关修改
								switch (index) {
									case 1: {
										that.open = false;
										break;
									}
									case 2: {
										that.private = false;
										break;
									}
									case 3: {
										that.someOneCan = false;
										that.someOneCanContent = 'content'
										break;
									}
									case 4: {
										that.someOneCanNot = false;
										that.someOneCanNotContent = 'content'
										break;
									}
								}
							}
							if (!that.open && !that.private && !that.someOneCan && !that.someOneCanNot) {
								that.open = true;
								uni.showToast({
									title: "默认权限为'公开'",
									duration: 2000,
									icon: 'none'
								});
								that.setRight(1);
							} else {
								
								//修改权限
								that.setRight(index);
							}

						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			setOpen(index) {
				this.switchModal('"公开"', index)
			},
			setPrivate(index) {
				this.switchModal('"私密"', index)
			},
			setSomeOneCan(index) {
				this.switchModal('"部分可见"', index);
			},
			setSomeOneCanNot(index) {
				this.switchModal('"不给谁看"', index)
			},
			//获取权限
			async getRight() {
				uni.showLoading({
				    title: '加载中..',
					mask: true
				});
				let that = this;
				let res = await getApp().UniRequest("/mita/authority/getPrivacySetting", "Get", "", this
					.header);
				// console.log('当前权限', res)
				if (res.code === 20000) {
					let setting = '';
					setting = res.data.setting;
					// console.log(typeof setting)
					switch (setting) {
						case 1: {
							that.open = true;
							uni.hideLoading()
							break;
						}
						case 2: {
							that.private = true;
							uni.hideLoading()
							break;
						}
						case 3: {
							that.someOneCan = true;
							that.someOneCanContent = 'someOneCanContent';
							uni.showLoading({
							    title: '加载中..',
								mask: true
							});
							that.detailPrivacygetting(3)
							

							break;
						}
						case 4: {
							that.someOneCanNot = true;
							that.someOneCanNotContent = 'someOneCanContent';
							uni.showLoading({
							    title: '加载中..',
								mask: true
							});
							that.detailPrivacygetting(4)
							

							break;
						}
					}
				}

			},
			//设置权限
			async setRight(index) {
				this.setRightParams.setting = index;
				// console.log('修改的权限', index)
				let res = await getApp().UniRequest("/mita/authority/privacySetting", "Get", this.setRightParams, this
					.header);
				// console.log('更改权限', res)
				if (res.code === 20000) {}

			},

			//查看只给谁看或不给谁看具体的人
			async detailPrivacygetting(index) {
				// console.log(index)
				let params = {
						setting: index
					}
				params.setting = index
				let res = await getApp().UniRequest("/mita/authority/detailPrivacySetting", "Get", params,
					this.header);
					// console.log(res)
					if (res.code === 20000) {
						if (index == 3) {
							this.someOneCanChoose = res.data.list;
							// console.log('只给某人看的数组', this.someOneCanChoose)
						} else if (index == 4) {
							this.someOneCanNotChoose = res.data.list;
							// console.log('不给某人看的数组', this.someOneCanNotChoose)
						}
					} else if (res.message == '没有数据') {
						if (index == 3) {
							this.someOneCanChoose = [];
							// console.log('只给某人看的数组', this.someOneCanChoose)
						} else if (index == 4) {
							this.someOneCanNotChoose = [];
							// console.log('不给某人看的数组', this.someOneCanNotChoose)
						}
					}
					uni.hideLoading()
			},

			addSomeOneCan() {
				uni.navigateTo({
					url: "../addMember/addMember?situation='addSomeOneCan'&miTaRight=1"
				});
			},
			deleteSomeOneCan() {
				uni.navigateTo({
					url: "../deleteMember/deleteMember?situation='addSomeOneCan'"
				});
			},
			addSomeOneCanNot() {
				uni.navigateTo({
					url: "../addMember/addMember?situation='addSomeOneCanNot'&miTaRight=1"
				});
			},
			deleteSomeOneCanNot() {
				uni.navigateTo({
					url: "../deleteMember/deleteMember?situation='addSomeOneCanNot'"
				});
			}
		}
	}
</script>

<style lang="scss" scoped="scoped">
	.page {
		padding: 30rpx;
		background-color: #f8f8f8;

		.right_item {
			height: 120rpx;
			padding: 10rpx;
			padding-top: 15rpx;
			width: 100%;
			display: flex;
			background-color: #f8f8f8;

			.right_discribe {
				width: 70%;
				display: flex;
				flex-direction: column;
				justify-content: center;

				.discribe_title {
					font-size: 34rpx;

				}

				.discribe_details {
					font-size: 26rpx;
					color: #8F8F8F;
					margin-top: 8rpx;
				}
			}

			.right_switch {
				width: 30%;
				text-align: right;

				switch {}
			}
		}

		.common {
			display: flex;
			flex-wrap: wrap;
		}

		.content {
			height: 0rpx;
			overflow: hidden;
			transition: 0.5s;
		}

		.someOneCanContent {
			transition: 0.5s;
			background-color: #f8f8f8;
			padding: 15rpx 5rpx 0rpx 20rpx;
		}

		.item {
			width: 100rpx;
			height: 100rpx;
			// background-color: pink;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			// border: 2rpx solid #000000;
			letter-spacing: 2rpx;
			color: #737373;

			.person_sex {
				font-size: 50rpx;
			}

			.person_name {
				font-size: 24rpx;


			}
		}

		.add {
			.icon-tianjia1 {
				font-size: 54rpx;
			}

			.icon-jianshao {
				font-size: 56rpx;
			}
		}
	}
</style>
